Skip to content

Fix Paint widget width/height and init_image sizing#182

Merged
koaning merged 4 commits intomainfrom
koaning/paint-height-fix
Mar 24, 2026
Merged

Fix Paint widget width/height and init_image sizing#182
koaning merged 4 commits intomainfrom
koaning/paint-height-fix

Conversation

@koaning
Copy link
Copy Markdown
Owner

@koaning koaning commented Mar 24, 2026

Summary

  • Canvas now respects width/height traitlets — previously it measured the DOM container, which in marimo stretches to fill the cell output, making the canvas much wider than requested.
  • init_image is resized to target dimensions upfrontget_pil() was returning the original image resolution before the first stroke, then jumping to the canvas buffer resolution after drawing. Now the image is resized in the Python constructor so the base64 always matches the canvas dimensions.

Test plan

  • Paint(width=300, height=250) renders a 300×250 canvas (not full-width)
  • Paint(init_image=url, height=300)get_pil() returns correct dimensions before any drawing
  • Drawing on an init_image canvas doesn't change the output resolution
  • Undo, clear, eraser still work correctly

🤖 Generated with Claude Code

koaning and others added 4 commits March 24, 2026 14:52
…atch

The canvas was sizing itself by measuring the DOM container, which in
marimo expands to fill the full cell output width. Now the canvas uses
the width and height traitlets directly as its buffer dimensions.

Also resizes init_image to match target dimensions before encoding to
base64, so get_pil() returns the correct resolution immediately instead
of only after the first stroke triggers a canvas export.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Drop tailwindcss from the js-paint build target (now just copies CSS).
Update paint demo with new examples (transparent mode, annotation).
Adjust zooming example slider ranges and formatting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Breaking release: Paint widget redesign (new toolbar, dropped Tailwind).
Empty canvases now start with a valid transparent PNG in base64 instead
of an empty string, so dimensions are always available from the start.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@koaning koaning merged commit c931a28 into main Mar 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant